package com.store.framework.db;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.sql.rowset.CachedRowSet;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.store.framework.dao.IAppWorksDao;
import com.store.framework.entry.AppWorksTbl;

public class AppWorksDao implements IAppWorksDao {
	private static Log LOG = LogFactory.getLog(AppWorksDao.class);

	public int add(AppWorksTbl app) {
		int a=0;
		String sql ="insert into app_works_tbl(Id,PerId,"
				+ "CompName,WbegDate,WendDate,Industry,"
				+ "Position,WAddDate,WaddPer,EditDate,"
				+ "EditPer,DelDate,DelPer,Del,Remarks) "
				+ "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		try {
			DaoUtil.executeUpdate(sql,app.getId(),app.getPerId(),
					app.getCompName(),app.getWbegDate(),
					app.getWendDate(),app.getIndustry(),
					app.getPosition(),app.getAddDate(),
					app.getWaddPer(),app.getEditDate(),
					app.getEditPer(),app.getDelDate(),
					app.getDelper(),app.getDel(),app.getRemarks()
			);
			a=1;
		} catch (SQLException e) {
			a=0;
			LOG.error(e.getMessage(),e);
			throw new RuntimeException(e.getMessage(),e);
		}
		return a;
	}

	public List<AppWorksTbl> select() {
		List<AppWorksTbl> list =new ArrayList<AppWorksTbl>();
		String sql ="select *from app_works_tbl";
		AppWorksTbl appworkstbl =new AppWorksTbl();
		try {
			CachedRowSet c=	DaoUtil.SimpleQuery(sql);
			while(c.next()){
				appworkstbl.setId(c.getString("Id"));
				appworkstbl.setPerId(c.getString("PerId"));
				appworkstbl.setCompName(c.getString("CompName"));
				appworkstbl.setWbegDate(c.getLong("WbegDate"));
				appworkstbl.setWendDate(c.getLong("WendDate"));
				appworkstbl.setIndustry(c.getString("Industry"));
				appworkstbl.setPosition(c.getString("Position"));
				appworkstbl.setAddDate(c.getLong("WAddDate"));
				appworkstbl.setWaddPer(c.getString("WaddPer"));
				appworkstbl.setEditDate(c.getLong("EditDate"));
				appworkstbl.setEditPer(c.getString("EditPer"));
				appworkstbl.setDelDate(c.getLong("DelDate"));
				appworkstbl.setDelper(c.getString("Delper"));
				appworkstbl.setDel(c.getLong("Del"));
				appworkstbl.setRemarks(c.getString("Remarks"));
				list.add(appworkstbl);
			}
		} catch (SQLException e) {
			list=null;
			LOG.error(e.getMessage(),e);
			throw new RuntimeException(e.getMessage(),e);
		}
 		
		return list;
	}

}
